package servlet;

import entity.AClass;
import entity.PageBean;
import entity.Student;
import service.ClassService;
import service.ClassServiceImpl;
import service.StudentService;
import service.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ClassPageQueryServlet",urlPatterns = "/classPageQueryServlet")
public class ClassPageQueryServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 1.获取前端页面传来的页码数值并构造分页查询的对象
        System.out.println("进来了。。。。。。。。。");
        String page = request.getParameter("page");
        //System.out.println("前台传过来的页码是：" + page);
        // 这里创建默认值为1，也就是第一个默认查询第一页数据内容
        PageBean pageBean = new PageBean(1, 10);
        if (null != page && page.length() > 0) {
            pageBean.setPage(Integer.parseInt(page));

        }
        // 通过Service层以及Dao层获取所有的学员信息
        ClassService classService = new ClassServiceImpl();
        List<AClass> classList = classService.classShowService(pageBean);
        // 将获取到的所有学员信息放到内置对象，通过客户端跳转的方式显示出来
        for(AClass aClass:classList){
            System.out.println(aClass);
        }
        request.getSession().setAttribute("classList", classList);
        System.out.println("准备重定位…");
        response.sendRedirect("manageClass.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
